# -*- coding: utf-8 -*-
"""
 @Time    : 2021/1/28 下午5:41
 @Author  : tgy
 
"""
import gzip
import tarfile
import os

def test01():
    with gzip.open('log.gz',mode='wt',encoding='utf-8') as f:
        f.write('哈哈')

def untar_gz():
    ...

    # tar = tarfile.open('./rocketmq.tar.gz')
    # for name in tar.getnames():
    #     ...
    #     tar.extract(name, path='./')
    # tar.close()
    with tarfile.open('./rocketmq.tar.gz') as tar:
        # for name in tar.getnames():
        #     tar.extract(name,path='./')
        # tar.extractall()
        ...

def tar_gz():
    ...
    last_file_name = 'aa.tar.gz'
    source_dir = '../第五章:文件与 IO'
    with tarfile.open(last_file_name,'w:gz') as tar:
        ...
        tar.add(source_dir,arcname=os.path.basename(source_dir))


if __name__ == '__main__':
    ...
    # test01()
    # untar_gz()
    tar_gz()